package com.heeexy.example.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.heeexy.example.dto.TeacherInfo;
import com.heeexy.example.service.TeacherService;
import com.heeexy.example.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author MyPC
 * @Date 2022/3/26 16:00
 * @description 老师相关Controller
 * @Version 1.0
 */
@RestController
@RequestMapping("/teacher")
public class TeacherContorller {

    @Autowired
    public void setTeacherService(TeacherService teacherService) {
        this.teacherService = teacherService;
    }

    private TeacherService teacherService;

    /**
     * 老师信息列表
     * @param request
     * @return listTeacher
     */
    @GetMapping("/listTeacher")
    public JSONObject listTeacher(HttpServletRequest request) {
        return teacherService.listTeacher();
    }

    @PostMapping("/importTeacherXls")
    public JSONObject importTeacherXls(MultipartFile file)  {
        return teacherService.saveTeacherXls(file);
    }

    @GetMapping("/outputTeacherXls")
    public void outputTeacherXls(HttpServletResponse response)  {
        teacherService.WriteTeacherXls(response);
    }

    @PostMapping("/saveTeacherInfo")
    public JSONObject saveTeacherInfo(@RequestBody JSONObject requestJson){
        return teacherService.saveTeacherInfo(requestJson);
    }
}
